package liverdungeon.gui;

//import java.awt.Color;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import liverdungeon.gui.LevelEditorApplet;
import liverdungeon.Account;
import liverdungeon.Global;
import liverdungeon.Level;
//import liverdungeon.leveleditor.*;

public class MainMenuFrame extends JFrame
{
    final int APP_WIDTH = 400;
    final int APP_HEIGHT = 225;
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();;
    
    
    public MainMenuFrame()
    {
        setTitle("JScrollPanes can suck my balls");
        setFrameProperties();
        this.add(getGameApplet());
    }

    private void setFrameProperties()
    {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setUndecorated(true);        //GETS RID OF THE FRAME
        Global.SCALE_FACTOR = getScale(screenSize);
        this.setBounds(0,0,screenSize.width,screenSize.height);
        this.setLayout(null);
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("images/ldIcon.png"));
        this.setAlwaysOnTop(true);
        this.setFocusable(true);
        this.setVisible(true);
    }

    public void paint(Graphics g)
    {
        g.setColor(Color.BLACK);
        g.fillRect(0,0,screenSize.width,screenSize.height);
    }
    
    private JApplet getGameApplet()
    {
        Global.applet = new MainMenuApplet(APP_WIDTH, APP_HEIGHT, this, null);
        return Global.applet;
    }
    
    public void launchLevelEditor(Account creator)
    {
        this.add(new LevelEditorApplet(creator, this));
    }
    
    public void launchGameApplet(Account a)
    {
        this.add(Global.applet);
    }
    
    public int getScale(Dimension screenSize)
    {
        int width = screenSize.width;
        int height = screenSize.height;

        int temp = width/APP_WIDTH;
        if(temp > height/APP_HEIGHT) temp = height/APP_HEIGHT;
        
        return temp;
    }
    
}
